package leetcode_301_400;

public class LeeCode_267 {
    public static void main(String[] args) {
        System.out.println(isPerfectSquare(16));
    }
    private static boolean isPerfectSquare(int num) {
        long n = num;
        long l = 0;
        long r = num;
        while (l < r){
            long m = (l + r) / 2;
            long fang = m * m;
            if (fang > n){
                r = m - 1;
            }else if (fang < n){
                l = m + 1;
            }else {
                return true;
            }
        }
        return l * l == n || r * r == n;
    }
}
